﻿using System;
using System.Web;

namespace Voluntariar.WEB.Util
{
    public partial class Download : PaginaBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Sessao.ArquivoDownload != null)
                {
                    if (string.IsNullOrEmpty(Sessao.NomeArquivoDownload))
                        Sessao.NomeArquivoDownload = "Voluntariar";

                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Sessao.NomeArquivoDownload + "\"");
                    HttpContext.Current.Response.AddHeader("Content-Length", Sessao.ArquivoDownload.Length.ToString());
                    HttpContext.Current.Response.ContentType = "application/octet-stream";
                    HttpContext.Current.Response.BinaryWrite(Sessao.ArquivoDownload);

                    Sessao.NomeArquivoDownload = string.Empty;
                    Sessao.ArquivoDownload = null;
                }
            }
        }
    }
}